import wx

# 自定义窗口类
class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super().__init__(parent, title=title, size=(300, 200))

        # 创建一个面板
        self.panel = wx.Panel(self)

        # 创建一个网格布局管理器
        grid_bag_sizer = wx.GridBagSizer( 5, 5)

        # 创建两个按钮
        self.button1 = wx.Button(self.panel, label="按钮1")
        self.button2 = wx.Button(self.panel, label="按钮2")
        self.button3 = wx.Button(self.panel, label="按钮3")
        self.button4 = wx.Button(self.panel, label="按钮4")
        self.button5 = wx.Button(self.panel, label="按钮5")
        self.button6 = wx.Button(self.panel, label="按钮6")

        # 将按钮添加到网格布局管理器中
        grid_bag_sizer.Add(self.button1, pos=(0, 0), flag=wx.EXPAND)
        grid_bag_sizer.Add(self.button2, pos=(1, 1), flag=wx.EXPAND)
        grid_bag_sizer.Add(self.button3, pos=(3, 3), flag=wx.EXPAND)
        grid_bag_sizer.Add(self.button4, pos=(2, 2), flag=wx.EXPAND)
        grid_bag_sizer.Add(self.button5, pos=(4, 1), flag=wx.EXPAND)
        grid_bag_sizer.Add(self.button6, pos=(2, 4), flag=wx.EXPAND)

        # 将网格布局管理器设置为面板的布局管理器
        self.panel.SetSizer(grid_bag_sizer)


if __name__ == "__main__":
    # 创建一个应用程序
    app = wx.App()
    # 创建一个窗口
    frame = MyFrame(None, title="Hello, wxPython!")
    # 显示窗口
    frame.Show()
    # 运行应用程序
    app.MainLoop()
